package com.qbw.core.holder;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.qbw.app.R;
import com.qbw.app.databinding.HolderEmptyBinding;
import com.qbw.core.base.BaseHolder;
import com.qbw.core.model.Empty;


/**
 * @author QBW
 * @createtime 2016/03/17 18:36
 * @company 9zhitx.com
 * @description 数据为0
 * 1.在适配器中使用的时候，通过bindData来显示或者隐藏
 * 2.不在适配器中使用的时候(bindData(new ErrorTipBean()),构造一个默认的ErrorTipBean对象，注册点击事件)，通过showErrorTip，hideErrorTip来显示或者隐藏
 */


public class EmptyHolder extends BaseHolder<Empty, HolderEmptyBinding> {

    private Listener mListener;

    public EmptyHolder(Context context, ViewGroup viewParent, Listener listener) {
        super(context, R.layout.holder_empty, viewParent);
        mListener = listener;
    }

    public void bindData(Empty data) {
        bindData(-1, data);
    }

    @Override
    public void bindData(int position, Empty data) {
        mBinding.setEmpty(data);
        mBinding.executePendingBindings();
        itemView.setOnClickListener(mItemClick);
        showEmptyText(data.getCode(), data.getMoudleId());
    }


    /**
     * 点击item
     */
    private View.OnClickListener mItemClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mListener) {
                mListener.onRetryGetData();
            }
        }
    };


    private void showEmptyText(int code, int moudleId) {
        switch (moudleId) {
            case ModelId.M_VEHICLE_MANAGE:
                mBinding.tvEmpty.setText(R.string.no_vehicle);
                break;
            case ModelId.M_VEHICLE_NO_ELECTRIC_AREA:
                mBinding.tvEmpty.setText(R.string.no_electric_area);
                break;
            case ModelId.M_VEHICLE_WARNING:
                mBinding.tvEmpty.setText(R.string.no_warning);
                break;
            case ModelId.M_VEHICLE_NO_TRAVEL:
                mBinding.tvEmpty.setText(R.string.no_travel);
                break;
            case ModelId.M_NO_NOTIFICATION_SET:
                mBinding.tvEmpty.setText(R.string.no_notification);
                break;
            default:
                break;
        }
    }

    public void setListener(Listener listener) {
        mListener = listener;
    }

    public interface Listener {
        void onRetryGetData();
    }

    public void setPadding(int left, int top, int right, int bottom) {
        itemView.setPadding(left, top, right, bottom);
    }

    public static class ModelId {
        public static final int M_VEHICLE_MANAGE = 1;
        public static final int M_VEHICLE_NO_ELECTRIC_AREA = 2;
        public static final int M_VEHICLE_WARNING = 3;
        public static final int M_VEHICLE_NO_TRAVEL = 4;
        public static final int M_NO_NOTIFICATION_SET = 5;
    }
}
